package com.eastfair.auth.api;

import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.database.mybatis.auth.DataScopeOfUserId;
import com.eastfair.auth.dto.OrganizationDTO;
import com.eastfair.auth.dto.OrganizationRoleDto;
import com.eastfair.auth.dto.UserOrganizationDTO;
import com.eastfair.auth.dto.UserRoleDto;
import com.eastfair.auth.entity.Organization;
import com.eastfair.auth.entity.UserOrganization;
import com.eastfair.auth.hystrix.AuthApiFallback;
import com.eastfair.auth.vo.OrganizationVo;
import com.eastfair.auth.vo.ResourceOrganizationVo;
import com.eastfair.core.base.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * auth feign接口
 *
 * @Author ligang
 * @Date 2021/7/16 16:41
 */
@FeignClient(name = "auth", fallback = AuthApiFallback.class)
public interface AuthServiceFeign {

    /**
     * 创建项目
     *
     * @param organizationDTO 实体
     * @return
     */
    @PostMapping("/projectOrganization/createProject")
    R<Organization> createProject(@RequestBody OrganizationDTO organizationDTO);


    /**
     * 修改项目
     *
     * @param organizationDTO 实体
     * @return
     */
    @PostMapping("/projectOrganization/updProject")
    R<Organization> updProjectOrganization(@RequestBody OrganizationDTO organizationDTO);


    /**
     * 添加组织关联角色
     *
     * @param orgRoleDto 组织角色实体
     * @return
     */
    @PostMapping("/organization/addOrgRole")
    R addOrgRole(@RequestBody OrganizationRoleDto orgRoleDto);


    /**
     * 更新组织关联角色
     *
     * @param orgRoleDto 组织角色实体
     * @return
     */
    @PostMapping("/organization/updOrgRole")
    R updOrgRole(@RequestBody OrganizationRoleDto orgRoleDto);


    /**
     * 通过资源查询角色Id集合
     *
     * @param resourceId 资源id
     * @return
     */
    @ApiOperation(value = "通过资源查询角色Id集合", notes = "通过资源查询角色Id集合")
    @GetMapping("/organization/queryRoleOfResourceId")
    R<List<Long>> queryRoleOfResourceId(@RequestParam("resourceId") Long resourceId);

    /**
     * 查询资源指定节点下的组织Id集合
     *
     * @param resourceId 资源id
     * @param orgId      指定节点id
     * @return
     */
    @ApiOperation(value = "查询资源指定节点下的组织Id集合", notes = "查询资源指定节点下的组织Id集合")
    @GetMapping("/organization/queryRoleOfOrgId")
    R<List<Long>> queryOrgOfResourceId(@RequestParam("resourceId") Long resourceId, @RequestParam("orgId") Long orgId);

    /**
     * 添加用户到组织
     *
     * @param userOrganizationDTO 用户组织实体
     * @return
     */
    @ApiOperation(value = "添加用户到组织", notes = "添加用户到组织")
    @PostMapping("/userOrganization/addUserOfOrg")
    R<UserOrganization> addUserOfOrg(@RequestBody UserOrganizationDTO userOrganizationDTO);


    /**
     * 查询 项目下的类型节点信息
     *
     * @param organizationDTO
     * @return
     */
    @ApiOperation(value = "查询资源指定节点下的组织Id集合", notes = "查询资源指定节点下的组织Id集合")
    @PostMapping("/organization/queryOrgOfType")
    R<Organization> queryOrgOfType(@RequestBody OrganizationDTO organizationDTO);


    /**
     * 通过组织查询资源
     *
     * @param orgIds 组织id
     * @return
     */
    @ApiOperation(value = "通过组织查询资源", notes = "通过组织查询资源")
    @GetMapping("/resourceOrganization/queryResource")
    R<List<ResourceOrganizationVo>> queryResource(@RequestParam("orgIds") List<Long> orgIds);

    @ApiOperation(value = "通过组织查询资源ID", notes = "通过组织查询资源ID")
    @GetMapping("/resourceOrganization/queryResourceId")
    R<List<Long>> queryResourceId(@RequestParam("orgIds") List<Long> orgIds);


    /**
     * 查询资源所在的指定组织里的信息
     *
     * @param orgIds 组织id
     * @return
     */
    @ApiOperation(value = "查询资源所在的指定组织里的信息", notes = "查询资源所在的指定组织里的信息")
    @GetMapping("/organization/queryOrgOfResource")
    R<Map<Long, List<Organization>>> queryOrgOfResource(@RequestParam("resourceIds") List<Long> resourceIds, @RequestParam("orgIds") List<Long> orgIds);


    /**
     * 查询用户权限信息，用于接口判断
     *
     * @param userIds
     * @return
     */
    @ApiOperation(value = "查询用户权限信息", notes = "查询用户权限信息")
    @GetMapping("/organization/loadUserPermission")
    R<List<Map>> loadUserPermission(@RequestParam("userIds") List<Long> userIds);


    /**
     * 根据组织查询用户的权限信息，用于接口判断
     *
     * @param orgIds
     * @return
     */
    @ApiOperation(value = "根据组织查询用户的权限信息", notes = "查询用户权限信息")
    @GetMapping("/organization/loadUserPermissionOfOrg")
    R<List<Map>> loadUserPermissionOfOrg(@RequestParam("orgIds") List<Long> orgIds);

    /**
     * 根据角色查组织进而查询用户的权限信息，用于接口判断
     *
     * @param roleIds
     * @return
     */
    @ApiOperation(value = "根据角色查组织进而查询用户的权限信息", notes = "根据角色查组织进而查询用户的权限信息")
    @GetMapping("/organization/loadUserPermissionOfRole")
    R<List<Map>> loadUserPermissionOfRole(@RequestParam("roleIds") List<Long> roleIds);


    /**
     * 通过用户查询菜单id
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "通过用户查询菜单id", notes = "通过用户查询菜单id")
    @GetMapping("/organization/queryMenuIdOfUser")
    R<List<Long>> queryMenuIdOfUser(@RequestParam("userId") Long userId);

    /**
     * 查询用户的数据权限规则
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "查询用户的数据权限规则", notes = "查询用户的数据权限规则")
    @GetMapping("/dataScope/queryDataScopeOfUserId")
    DataScopeOfUserId queryDataScopeOfUserId(@RequestParam("userId") Long userId);


    /**
     * 查询id集合
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "查询id集合", notes = "查询id集合")
    @GetMapping("/organization/queryList")
    R<List<OrganizationVo>> queryList(@RequestParam("ids") List<Long> ids);

    /**
     * 添加用户关联角色
     * addUserRole
     *
     * @param userRoleDto 用户角色实体
     * @return
     */
    @ApiOperation(value = "添加用户关联角色", notes = "添加用户关联角色")
    @PostMapping("/userRole/addUserRole")
    R addUserRole(@RequestBody UserRoleDto userRoleDto);

    /**
     * 更新用户关联角色
     *
     * @param userRoleDto 用户角色实体
     * @return
     */
    @ApiOperation(value = "更新用户关联角色", notes = "更新用户关联角色")
    @PostMapping("/userRole/updUserRole")
    R updUserRole(@RequestBody UserRoleDto userRoleDto);


    /**
     * 剔除用户关联角色
     *
     * @param userRoleDto 组织角色实体
     * @return
     */
    @ApiOperation(value = "剔除用户关联角色", notes = "剔除用户关联角色")
    @PostMapping("/userRole/removeUserRole")
    R removeOrgRole(@RequestBody UserRoleDto userRoleDto);

    /**
     * 查询用户关联角色
     *
     * @param userRoleDto 组织角色实体
     * @return
     */
    @ApiOperation(value = "查询用户关联角色", notes = "查询用户关联角色")
    @PostMapping("/userRole/queryUserRole")
    R queryUserRole(@RequestBody UserRoleDto userRoleDto);


    /**
     * 添加用户到组织
     *
     * @param organizationDTO 组织实体
     * @return
     */
    @ApiOperation(value = "添加用户到组织", notes = "添加用户到组织")
    @PostMapping("/organization/trasactionTest")
    R trasactionTest(@RequestBody OrganizationDTO organizationDTO);


    /**
     * 创建节点组     * @return
     *
     * @param organizationDTO 组织实体
     */
    @ApiOperation(value = "创建节点组", notes = "创建节点组")
    @PostMapping("/organization/createOrgGroup")
    R createOrgGroup(@RequestBody OrganizationDTO organizationDTO);

    /**
     * 查询用户所在的组织
     * @param organizationDTO
     * @return
     */
    @ApiOperation(value = "查询用户所在的组织", notes = "查询用户所在的组织")
    @PostMapping("/organization/queryOrgOfUserId")
    R<Map<Long, List<OrganizationVo>>> queryOrgOfUserId(@RequestBody OrganizationDTO organizationDTO);


    /**
     * 查询子组织id
     *
     * @param organizationDTO
     * @return
     */
    @ApiOperation(value = "查询子组织id", notes = "查询子组织id")
    @PostMapping("/organization/queryChildOrgIdOfOrgId")
    R<List<Long>> queryChildOrgIdOfOrgId(@RequestBody OrganizationDTO organizationDTO);

}
